package Aleehot100;

/**
 * ClassName: c077
 * Package: Aleehot100
 * Description:121. 买卖股票的最佳时机
 *
 * @Author BCXJ
 * @Create 2025/9/3 08:32
 * @Version 1.0
 * @Since 1.0
 */
public class c077 {
    public static void main(String[] args) {

    }

    public static int maxProfit(int[] prices) {
        int preMin = Integer.MAX_VALUE;
        int profile = 0; //  利润
        for (int price : prices) {
            if(price < preMin) {
                preMin = price;
            }
            if(price - preMin > profile) {
                profile = price - preMin;
            }
        }
        return profile;
    }
}
